package main

import (
	"fmt"
	"net/http"
	"time"
)

func main() {
	http.HandleFunc("/hello",hello)
	http.ListenAndServe(":8090",nil)
}

func hello(w http.ResponseWriter, r *http.Request) {
	context := r.Context()
	fmt.Println("server: hello handler started")
	defer fmt.Println("server: hello handler ended")

	select {
	case <-time.After(10 * time.Second):
		fmt.Fprintf(w,"hello\n")
	case <-context.Done():
		err:=context.Err()
		fmt.Println("server: ",err)
		internalError := http.StatusInternalServerError
		http.Error(w,err.Error(),internalError)
	}
}